﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;
namespace IHISCETeim.BLL
{
    public  class SAreaManagerAgentController
    {
        /// <summary>
        /// 添加区域经理所属经销商
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int Add(SAreaManagerAgentInfo obj)
        {
            return SAreaManagerAgentDAL.Add(obj);
        }
        public static bool Delete(int ID)
        {
            return SAreaManagerAgentDAL.Delete(ID);
        }
        /// <summary>
        /// 根据区域经理UserId 获取其所有的经销商列表
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public static List<SAreaManagerAgentInfo> GetAllByUserId(int UserId)
        {
            return CBO.FillCollection<SAreaManagerAgentInfo>( SAreaManagerAgentDAL.GetAllByUserId(UserId));
        }
        /// <summary>
        /// 获取当前登陆用户所属经销商SQL查询条件
        /// 格式为 '''营业一部'',''风险部'''
        /// </summary>
        /// <returns></returns>
        public static string GetMyAgentSqlWhere()
        {
            
            return GetMyAgentSqlWhere(OUserController.CurrentUser.UserId);
        }
     
        /// <summary>
        /// 获取当前登陆用户所属经销商SQL查询条件
        /// 格式为 '''营业一部'',''风险部'''
        /// </summary>
        /// <returns></returns>
        public static string GetMyAgentSqlWhere(int UserId)
        {
            OUserInfo obj=  OUserController.GetById(UserId);
            if (obj.IsSuperAdmin)
                return "";
            //int userid = OUserController.CurrentUser.UserId;
            List<SAreaManagerAgentInfo> listArea = GetAllByUserId(UserId);
            ///格式为 '''营业一部'',''风险部'''
            if (listArea == null || listArea.Count == 0)
                return "";
            string sqlwhere = "";
            foreach (SAreaManagerAgentInfo itm in listArea)
            {
                sqlwhere += string.Format("'{0}',", itm.AliasName);
            }

            sqlwhere = sqlwhere.Substring(0, sqlwhere.Length - 1);

            return sqlwhere;
        }


    }
}
